define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yjy_house/index' + location.search,
                    add_url: 'yjy_house/add',
                    edit_url: 'yjy_house/edit',
                    del_url: 'yjy_house/del',
                    multi_url: 'yjy_house/multi',
                    table: 'yjy_house',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'Id',
                sortName: 'Id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'Id', title: __('Id')},
                        {field: 'title', title: __('Title')},
                        {field: 'location_near', title: __('Location_near')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},

                        {field: 'price', title: __('Price')},
                        {field: 'collect', title: __('Collect'), operate:'BETWEEN'},
                        {field: 'is_recommend', title: __('Is_recommend'), searchList: {"0":__('Is_recommend 0'),"1":__('Is_recommend 1')}, formatter: Table.api.formatter.normal},
                        {field: 'house_area', title: __('House_area')},
                        {field: 'house_floor', title: __('House_floor')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'house_status', title: __('House_status'), searchList: {"1":__('House_status 1'),"2":__('House_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'lon', title: __('Lon'), operate:'BETWEEN'},
                        {field: 'lat', title: __('Lat'), operate:'BETWEEN'},
                        {field: 'location_map', title: __('Location_map')},
                        {field: 'user.mobile', title: __('经纪人手机号')},
                        {field: 'user.nickname', title: __('经纪人昵称')},

                        {field: 'yjyhousearea.name', title: __('Yjyhousearea.name')},

                        {field: 'yjyhouselandlord.name', title: __('房东姓名')},
                        {field: 'yjyhouselandlord.mobile', title: __('房东手机号')},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {name: 'order', text: '预约', title: '预约', icon: 'fa fa-play', classname: 'btn btn-xs btn-success btn-dialog',url:'yjy_house/order'},
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        order: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});